		scope.pageCourseManagement = function(page){
			$("input[name='slectAll']").prop("checked",false);
			$("input[name='coursebox']").prop("checked",false);
			var maxCount = 10;
			var min = ( page - 1 ) * maxCount;
			if( min < 0 || min >= scope.tempCourseList.length )
				return ;
			scope.courseList = [];
			for( var i = 0; i < maxCount && ( min + i + 1 ) <= scope.tempCourseList.length;i++ ){
				scope.courseList[i] = scope.tempCourseList[min + i];
			}
			scope.courseManagementPage = page;
		}

		scope.courseManagement = function(onsuccess){
			
			shutAllPages(scope);
			http.post("GetAllCourseInfo.action").success(function(response) {
				console.log(response);		
				scope.tempCourseList = response;
				scope.courseManagementPage = 1;
				scope.courseList = [];
				for( var i = 0; i < 10 && i < scope.tempCourseList.length ; i++ ){
					scope.courseList[i] = scope.tempCourseList[i];
				}
				onsuccess();
			});
			/*$('input:checkbox').each(function () {
        		$(this).attr('checked',false);
			});*/
			$("input[name='slectAll']").prop("checked",false);
			$("input[name='coursebox']").prop("checked",false);
			
			scope.accountShow=true;
		};

		scope.insertCourse = function(){
			var courseId = document.getElementsByName("courseId")[0].value;
			var courseName = document.getElementsByName("courseName")[0].value;
			var courseTeacher = document.getElementsByName("courseTeacher")[0].value;
			var courseTime =  document.getElementsByName("courseTime")[0].value;
			var courseRoom = document.getElementsByName("courseRoom")[0].value;

			http.post("InsertCourseInfo.action", {"courseId" : courseId, "courseName" : courseName, "courseTeacher" : courseTeacher, "courseTime" : courseTime,  "courseRoom" : courseRoom}).success(function(response) {
				onsuccess = function(){
					var i = parseInt(scope.tempCourseList.length / 10);
					console.log(i);
					if(  scope.tempCourseList.length % 10 == 0 ){
						scope.pageCourseManagement(i);
					}
					else{
						scope.pageCourseManagement(i+1);
					}
				}
				scope.courseManagement(onsuccess);

				return;
				}).error(function(response){
					alert(response);
				}); 
			
		};
		


		scope.deleteCourse = function(courseId) {
			var courseIdList = new Array();
			if (courseId != null) {
				courseIdList.push(courseId);
			} else {
				$("input[name='coursebox']:checked").each(function() {
					courseIdList.push(this.value);
				});
			}
			if (courseIdList.length <= 0) {
				alert("请至少选择一个需要删除的项！");
				return;
			}
			http.post("DeleteCourseAction.action", { "courseIdList" : courseIdList }).success(function(response) {
				if (response.indexOf("success") > -1) {
					alert("操作成功！");
					onsuccess = function(){
						var i = parseInt((scope.tempCourseList.length - 1) / 10);
						console.log(i);
						if(  scope.tempCourseList.length % 10 == 0 ){
							scope.pageCourseManagement(i - 1);
						}
						else{
							scope.pageCourseManagement(i);
						}
					}
					scope.courseManagement(onsuccess);
					return;
				} else {
					alert(response);
				}
			}).error(function(response){
				alert(response);
			});
		};
		
		scope.showTeacher = function(teacherId){
			http.post("GetUserInfoById.action?userId=" + teacherId).success(function(response) {
				alert(response);
				console.log("response",response);
			}).error(function(response){
				alert(response);
			});
		};